package com.example.wechatdaka.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.wechatdaka.entity.Checkwork;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lx
 * @since 2020-11-30
 */
public interface CheckworkMapper extends BaseMapper<Checkwork> {
    @Select("select k.id,k.lxUserId,u.lxUsername,k.lxCheckWorkName,k.lxClazzId,k.lxClazzName,k.lxCheckAging,k.lxReleaseTime \n" +
            "from lx_checkwork k\n" +
            "left join lx_user u on k.lxUserId = u.id ORDER BY k.lxReleaseTime DESC")
    public IPage<Checkwork> queryAll(Page page);
    @Select("select k.id,k.lxUserId,u.lxUsername,k.lxCheckWorkName,k.lxClazzId,k.lxClazzName,k.lxCheckAging,k.lxReleaseTime \n" +
            "from lx_checkwork k\n" +
            "left join lx_user u on k.lxUserId = u.id\n" +
            "where k.lxUserId in(select id from lx_user where lxUsername like concat('%',#{keyword},'%')) ORDER BY k.lxReleaseTime DESC")
    public IPage<Checkwork> queryByTeacherKeyword(Page page,String keyword);
    @Select("select k.id,k.lxUserId,u.lxUsername,k.lxCheckWorkName,k.lxClazzId,k.lxClazzName,k.lxCheckAging,k.lxReleaseTime \n" +
            "from lx_checkwork k\n" +
            "left join lx_user u on k.lxUserId = u.id\n" +
            "where k.lxCheckWorkName like concat('%',#{keyword},'%') ORDER BY k.lxReleaseTime DESC")
    public IPage<Checkwork> queryByKeyword(Page page,String keyword);
    @Select("select k.id,k.lxUserId,u.lxUsername,k.lxCheckWorkName,k.lxClazzId,k.lxClazzName,k.lxCheckAging,k.lxReleaseTime \n" +
            "from lx_checkwork k \n" +
            "left join lx_user u on k.lxUserId = u.id \n" +
            "where k.lxUserId=#{id}\n" +
            "ORDER BY k.lxReleaseTime DESC")
    public IPage<Checkwork> queryAllByTeaId(Page page,String id);
    @Select("select k.id,k.lxUserId,u.lxUsername,k.lxCheckWorkName,k.lxClazzId,k.lxClazzName,k.lxCheckAging,k.lxReleaseTime \n" +
            "from lx_checkwork k \n" +
            "left join lx_user u on k.lxUserId = u.id \n" +
            "where k.id=#{checkId}")
    public Checkwork queryByIdMini(String checkId);
    //根据班级id和签到id查询未签到学生\
    @Select("select u.lxUserNumber\n" +
            "from  lx_user_student us\n" +
            "left join lx_user u on us.lxUserId=u.id\n" +
            "left join lx_clazz c on us.lxClazzId=c.id\n" +
            "where u.lxUserNumber not in(select lxUserNumber from  lx_signin where lxCheckworkId=#{checkId})\n" +
            "and c.id=#{clazzId}")
    public List<String> queryUnSignByClazz(String clazzId,String checkId);
}
